<template>
  <div
    id="home"
    v-loading="!isLoad"
    element-loading-text="数据年份切换中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <div class="head">
      <div class="h_left">
        <div class="excel">
          <i class="iconfont icon-Excel"></i>
          <span>导出excel</span>
        </div>
        <div class="img">
          <i class="iconfont icon-img"></i>
          <span>导出图片</span>
        </div>
        <div class="year" @click="dialogVisible=true">
          <i class="iconfont icon-qiehuan"></i>
          <span>切换日期</span>
        </div>
      </div>
      <div class="h_center">
        <div class="title">廊坊市{{$store.state.YEAR}}年卫生监督可视化大数据分析</div>
        <div class="nav">
          <div class="befor"></div>
          <div class="zhongjian"></div>
          <div @click="changNav('/')" :class="activeLink==='/'?'nav_li active':'nav_li'">监督概况</div>
          <div class="zhongjian"></div>
          <div
            @click="changNav('/zhuanye')"
            :class="activeLink==='/zhuanye'?'nav_li active':'nav_li'"
          >分专业展示</div>
          <div class="zhongjian"></div>
          <div
            @click="changNav('/more')"
            :class="activeLink==='/more'?'nav_li active':'nav_li'"
          >更多概况</div>
          <div class="zhongjian"></div>
          <div class="after"></div>
        </div>
      </div>
      <div class="h_right">
        <div class="user_warp">
          <div class="left">
            <img src="../assets/mao.png" alt />
            <div class="wenzi">
              管理员，欢迎您的登录
              <br />上次登录时间：2020-2-14
            </div>
            
          </div>
          <div class="right_out">
            <i title="退出" class="iconfont icon-dianyuan"></i>
          </div>
        </div>
      </div>
    </div>
    <div class="top_bar">
      <div class="xiaoxi">
        <i class="iconfont icon-xiazai41"></i>
        <div class="title">{{xiaoxi}}</div>
      </div>
      <div class="time">{{time}}</div>
    </div>
    <el-dialog title="请选择切换的年份" :visible.sync="dialogVisible" width="30%">
      <!-- <span style="display:block;text-align: center;line-height:3em;">请选择切换的年份</span> -->
      <div style="display:flex;justify-content: space-evenly;">
        <el-button
          v-for="val of yearArr"
          @click="changeYear(val)"
          type="primary"
          round
          :key="val"
        >{{val}}</el-button>
        <!-- <el-button @click="changeYear(2020)" type="primary" round>2019</el-button>
        <el-button @click="changeYear(2020)" type="primary" round>2018</el-button>-->
      </div>

      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>-->
    </el-dialog>
    <router-view v-if="isLoad"></router-view>
  </div>
</template>

<script>
import { formatTimeToStr, getXingQi } from "../assets/date";
export default {
  name: "Home",
  data() {
    return {
      isLoad: true,
      yearArr: [],
      dialogVisible: false,
      activeLink: "/",
      time: "星期三 2020.02.12",
      xiaoxi:
        "重要消息：今日廊坊新型冠状病毒最新数据播报新增1例，累计确诊29例，死亡0例，治愈11例"
    };
  },
  methods: {
    createYearArray() {
      const year = this.$store.state.YEAR;
      this.yearArr = [year, year - 1, year - 2];
    },
    changeYear(e) {
      this.$store.commit("setYear", e);

      this.isLoad = false;
      setTimeout(() => {
        this.isLoad = true;
        this.$message({
          message: `数据信息以为您切换到${e}年`,
          type: "success",
          center: true
        });
      }, 1000);
      this.dialogVisible = false;
    },
    changNav(e) {
      this.activeLink = e;
      this.$router.push(e);
    },
    getTime() {
      let xiqing = getXingQi(new Date());
      this.time = xiqing + " " + formatTimeToStr(new Date(), "yyyy-MM-dd");
    }
  },
  watch: {},
  mounted() {
    this.createYearArray();
    this.activeLink = this.$route.path;
    setInterval(() => {
      this.getTime();
    }, 1000);
  }
};
</script>
<style lang="less">
#home {
  height: 100vh;
  background: url(../assets/xkbg.jpg) no-repeat;
  background-size: 100% 100%;

  .head {
    height: 2.75rem;
    background-color: #07163ebf;
    display: flex;
    justify-content: space-between;
    position: relative;

    .h_left {
      flex: 1;
      display: flex;
      align-items: center;
      padding: 0 1.625rem;
      border-bottom: 0.125rem solid #233669;

      & > div {
        margin-right: 0.625rem;
        padding: 0.125rem 0.3125rem;
        border-radius: 0.25rem;
        border: 0.0625rem solid red;

        &:hover {
          cursor: pointer;
        }
      }

      .iconfont {
        font-size: 1.25rem;
        margin-right: 0.3125rem;
      }

      .excel {
        border-color: #97bb5b;
        color: #97bb5b;
      }
      .year {
        border-color: #CC9999;
        color: #CC9999;
      }

      .img {
        border-color: #4c9dcc;
        color: #4c9dcc;
      }
    }

    .h_center {
      flex: 1.6;
      text-align: center;

      .title {
        color: whitesmoke;
        font-size: 1.6rem;
        position: relative;
        bottom: -0.35rem;
      }

      .nav {
        height: 2.75rem;
        background-color: #07163ebf;
        margin-top: 0.6rem;
        line-height: 2.75rem;
        display: flex;
        color: #07ccff;
        overflow: hidden;

        .befor {
          background: url(../assets/nav_left.png) no-repeat;
          background-size: 100% 100%;
          width: 5rem;
        }

        .nav_li {
          flex: 1;
          background: url(../assets/nav_ac.png) no-repeat;
          background-size: 100% 0.693rem;
          background-position: bottom;
          font-size: 1.25rem;
          line-height: 2rem;

          &:hover {
            cursor: pointer;
          }
        }

        .zhongjian {
          flex: 0.4;
          background: url(../assets/nav_ac.png) no-repeat;
          background-size: 200% 0.693rem;
          background-position: bottom;
        }

        .active {
          background: url(../assets/nav_bot.png) no-repeat;
          background-size: 100% 0.693rem;
          background-position: bottom;
        }

        .after {
          background: url(../assets/nav_right.png) no-repeat;
          background-size: 100% 100%;
          width: 5rem;
        }
      }
    }

    .h_right {
      flex: 1;
      display: flex;
      flex-direction: row-reverse;
      color: whitesmoke;
      padding: 0 1.625rem;
      border-bottom: 0.125rem solid #233669;

      .user_warp {
        display: flex;
        align-items: center;

        .left {
          display: flex;
          align-items: center;
          font-size: 0.75rem;

          img {
            width: 2.5rem;
            margin-right: 0.625rem;
          }
        }

        .right_out {
          margin-left: 1.875rem;

          .iconfont {
            font-size: 1.8rem;

            &:hover {
              cursor: pointer;
            }
          }
        }
      }
    }
  }

  .top_bar {
    display: flex;
    justify-content: space-between;
    color: #07ccff;
    height: 3.5rem;
    background-color: #051537;
    padding: 0 1.625rem;

    .xiaoxi {
      display: flex;
      align-items: center;
      width: 28%;

      .iconfont {
        font-size: 1.625rem;
        margin-right: 0.625rem;
      }

      .title {
        font-size: 0.875rem;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
      }
    }

    .time {
      width: 30%;
      font-size: 1.625rem;
      text-align: right;
      line-height: 3.5rem;
    }
  }
}
</style>
